How do you rename a file in C#?
How do you rename a file in C#? Explain with example and code.
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
29-May-2025In C#, you can rename a file using the
File.Movemethod from theSystem.IOnamespace. Here's how you do it:Rename a File in C#
Notes:
This also moves the file if the destination path is in a different directory.
If
destinationPathalready exists, it will throw anIOException.You can check if the file exists before renaming: